package com.yizhu.zczy.system.verification;


import com.yizhu.zczy.system.util.VCodeUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


/**
 * 生成验证码
 */
@Controller
@RequestMapping("/verify")
public class VerifyCodeController {

    @RequestMapping("/code")
    public void generateCode(HttpServletResponse response, HttpSession session){
        VCodeUtils vc = new VCodeUtils();
        try {
            response.setContentType("images/*");
            VCodeUtils.saveImage(vc.getImage(), response.getOutputStream());
            String verifyCode = vc.getText();
            System.out.println("生成的验证码"+verifyCode);
            session.setAttribute("verifyCode",verifyCode);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
